<template>
	<view class="test-page">
		<view class="test-header">
			<text class="test-title">新增门店页面测试</text>
		</view>
		
		<view class="test-content">
			<view class="test-item" @click="testAPI">
				<text class="test-text">测试API调用</text>
			</view>
			
			<view class="test-item" @click="testStats">
				<text class="test-text">测试统计数据</text>
			</view>
			
			<view class="test-item" @click="goToInsertStore">
				<text class="test-text">跳转到新增门店页面</text>
			</view>
		</view>
		
		<view class="test-result" v-if="testResult">
			<text class="result-title">测试结果:</text>
			<text class="result-text">{{ testResult }}</text>
		</view>
	</view>
</template>

<script>
import { getMockInsertStoreList, getMockInsertStoreStats } from '../../api/insertStore'

export default {
	name: 'InsertStoreTest',
	data() {
		return {
			testResult: ''
		}
	},
	methods: {
		async testAPI() {
			try {
				uni.showLoading({ title: '测试中...' })
				
				const res = await getMockInsertStoreList({
					page: 1,
					pageSize: 10,
					province: '重庆'
				})
				
				console.log('API测试结果:', res)
				
				this.testResult = `获取到${res.data.list.length}条门店数据`
				
				uni.hideLoading()
				uni.showToast({
					title: 'API测试成功',
					icon: 'success'
				})
			} catch (error) {
				uni.hideLoading()
				console.error('API测试失败:', error)
				this.testResult = 'API测试失败'
				uni.showToast({
					title: 'API测试失败',
					icon: 'error'
				})
			}
		},
		
		async testStats() {
			try {
				uni.showLoading({ title: '测试中...' })
				
				const res = await getMockInsertStoreStats({
					province: '重庆',
					month: new Date().getMonth() + 1
				})
				
				console.log('统计数据测试结果:', res)
				
				this.testResult = `本月新增门店: ${res.data.monthlyNewStores}家`
				
				uni.hideLoading()
				uni.showToast({
					title: '统计数据获取成功',
					icon: 'success'
				})
			} catch (error) {
				uni.hideLoading()
				console.error('统计数据测试失败:', error)
				this.testResult = '统计数据测试失败'
				uni.showToast({
					title: '统计数据测试失败',
					icon: 'error'
				})
			}
		},
		
		goToInsertStore() {
			uni.navigateTo({
				url: '/pagesData/pages/insert-store/index'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.test-page {
	padding: 20px;
	background-color: #f5f6fa;
	min-height: 100vh;
}

.test-header {
	text-align: center;
	margin-bottom: 30px;
	
	.test-title {
		font-size: 18px;
		font-weight: bold;
		color: #333;
	}
}

.test-content {
	.test-item {
		background-color: #fff;
		margin-bottom: 15px;
		padding: 20px;
		border-radius: 8px;
		text-align: center;
		
		&:active {
			background-color: #f0f0f0;
		}
		
		.test-text {
			font-size: 16px;
			color: #007aff;
		}
	}
}

.test-result {
	background-color: #fff;
	margin-top: 20px;
	padding: 20px;
	border-radius: 8px;
	
	.result-title {
		font-size: 14px;
		color: #666;
		display: block;
		margin-bottom: 10px;
	}
	
	.result-text {
		font-size: 16px;
		color: #333;
	}
}
</style>
